﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Visio;
using MODELENGLib;


namespace Founder.PKURG.VisioReader
{
    class Program
    {
        static void Main(string[] args)
        {
            //string path = @"C:\Users\zhangweixing\Desktop\项目信息管理\test.vsd";
            string path = @"C:\OrthogonalToolBoxExport3.xml";
          List<EntityInfo> ls=  VisioXMLReader.GetEntites(path);
            //NewMethod(path);
        }

        private static void NewMethod(string path)
        {
            Application app = new ApplicationClass();
            short flags = (short)VisOpenSaveArgs.visOpenDocked | (short)VisOpenSaveArgs.visOpenRO;

            Document doc = app.Documents.OpenEx(path, flags);

            VME vME = new VME();

            IEnumIVMEModels models = vME.vme.Models;

            foreach (Shape item in doc.Pages.get_ItemFromID(0).Shapes)
            {
                Console.WriteLine("{0}", item.Text);
            }

            int a = doc.Masters.Count;
            string b = doc.Masters[1].Name;
            Shape shape = doc.Masters.get_ItemFromID(6).Shapes[1];
            if (shape != null)
            {
                List<VisioPropertyInfo> propInfos = GetPropertyCollection(shape);
            }

            doc.Close();
            app.Quit();
        }

 


        //根据模具，获取属性对象集合
        public static List<VisioPropertyInfo> GetPropertyCollection(Shape shape)
        {
            List<VisioPropertyInfo> list = new List<VisioPropertyInfo>();
            VisioPropertyInfo propertyInfo;
            Cell shapeCell;
            short shortSectionProp = (short)VisSectionIndices.visSectionProp;

            if (shape != null)
            {
                for (short i = 0; i < shape.get_RowCount(shortSectionProp) - 1; i++)
                {
                    if (shape.get_CellsSRCExists(shortSectionProp, i, (short)VisCellIndices.visCustPropsLabel, 0) != 0)
                    {
                        propertyInfo = new VisioPropertyInfo();

                        shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsLabel);
                        propertyInfo.Name = VisioUtility.FormulaStringToString(shapeCell.RowNameU);

                        shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsPrompt);
                        propertyInfo.Prompt = VisioUtility.FormulaStringToString(shapeCell.FormulaU);

                        shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsFormat);
                        propertyInfo.Format = VisioUtility.FormulaStringToString(shapeCell.FormulaU);

                        shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsValue);
                        propertyInfo.Value = VisioUtility.FormulaStringToString(shapeCell.FormulaU);

                        shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsSortKey);
                        propertyInfo.Sort = VisioUtility.FormulaStringToString(shapeCell.FormulaU);

                        //shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsType);
                        //propertyInfo.PropType = VisioUtility.FormulaStringToString(shapeCell.FormulaU);

                        //shapeCell = shape.get_CellsSRC(shortSectionProp, i, (short)VisCellIndices.visCustPropsInvis);
                        //propertyInfo.InVisible = VisioUtility.FormulaStringToString(shapeCell.FormulaU);

                        //..
                        list.Add(propertyInfo);
                    }
                }
            }

            return list;
        }

    }
}
